using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SmartContentUI.Admin.Content
{
    public partial class ContainerContent : UserControl
    {
        #region Variables
        public delegate void saveContent(string name, string desc, int parentId);
        public delegate void cancelContent();
        public event saveContent saveContainer;
        public event cancelContent cancelContainer;

        private int parentId;
        #endregion

        #region Constructor
        public ContainerContent()
        {
            InitializeComponent();
            parentId = -1;
        }
        #endregion

        #region Form Events
        private void tb_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar == (char)Keys.Enter)
                save();
            if (e.KeyChar == (char)Keys.Escape)
                cancel();
        }

        private void save_btn_Click(object sender, EventArgs e)
        {
            save();
        }
        private void cancel_btn_Click(object sender, EventArgs e)
        {
            cancel();
        }
        #endregion

        #region Functions
        public void clearForm()
        {
            this.name_tb.Text = "";
            this.desc_tb.Text = "";
        }
        private void save()
        {
            if(name_tb.Text.Trim().Length == 0)
            {
                MessageBox.Show("Indique el nombre del contenedor");
                return;
            }
            if(MessageBox.Show("Desea guardar expediente?", "Agregar Contenedor", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                saveContainer(name_tb.Text.Trim(), desc_tb.Text.Trim(), parentId);
        }
        private void cancel()
        {
            if (MessageBox.Show("Desea salir sin guardar los cambios?", "Agregar Contenedor", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                cancelContainer();
        }
        public void setParent(int parentId)
        {
            this.parentId = parentId;
        }
        #endregion
    }
}
